<?php

namespace common\traits;

use Yii;
use common\helpers\ArrayHelper;

/**
 * Description of Constants
 *
 * @author emhome
 */
trait DataPierces {

    private $_pierces;

    public function setPierces($pierces) {
        $this->_pierces = $pierces;
    }

    public function getPierces($key = null, $default = null) {
        $data = $this->_pierces;
        if ($key !== null) {
            return ArrayHelper::getValue($data, $key, $default);
        }
        return $data;
    }

    private static $_extraAttributes = [];

    public function setExtraAttributes(array $data) {
        if (!empty($data)) {
            self::$_extraAttributes = $data;
        }
    }

    public function getExtraAttributes() {
        return (array) self::$_extraAttributes;
    }

    public function getExtraAttribute($attribute) {
        $extraAttributes = $this->getExtraAttributes();
        return ArrayHelper::getValue($extraAttributes, $attribute);
    }

}
